import { _decorator, AudioClip, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

import { SSS_Consts } from "../../../../Script/Data/SSS_Consts";
import { bdlMgr } from "../../../../Script/Manager/BundleManager_S";
import SSS_GameEventManager, { SS_GameEventData } from "../../../../Script/Manager/SSS_GameEventManager";
import { SSS_AudioManager } from "../../../../Script/Manager/SSS_AudioManager";

@ccclass('CircleTheCatWinPanel')
export default class CircleTheCat_WinPanel extends Component {
    public static Instance: CircleTheCat_WinPanel;
    @property(Node)
    public Button_menu: Node | null = null;
    @property(Node)
    public Button_replay: Node | null = null;
    // @property(Label)
    // public Label_time_current: Label = null;
    // @property(Label)
    // public Label_step_number_current: Label = null;
    // @property(Label)
    // public Label_time_record: Label = null;
    // @property(Label)
    // public Label_step_number_record: Label = null;
    onLoad() {
        CircleTheCat_WinPanel.Instance = this;
    }
    ShowOn() {
        this.node.active = true;
        this.AddListener();
        this.Refresh();

        // let audio_root = `audio/level complete`;
        let r = 4;
        let audio_root = `audio/Win sound/Win sound ${r}`;
        console.log(`audio_root`, audio_root);

        bdlMgr.getRes<AudioClip>(SSS_Consts.BundleName.AUDIO, audio_root, AudioClip).then(res => {
            SSS_AudioManager.Instance.playSFX(res, false);
        });
    }

    ShowOff() {
        this.node.active = false;
        this.RemoveListener();
    }
    async Refresh() {
        // this.Label_time_current.string = ShuZiHuaRongDao_GameData.Get_time_format(ShuZiHuaRongDao_GameManager.Instance.timer.getComponent(ShuZiHuaRongDao_Timer).elapsedTime);
        // this.Label_step_number_current.string = `${ShuZiHuaRongDao_GameData.step_number}`;

        // this.Label_time_record.string = ShuZiHuaRongDao_GameData.Get_time_format(ShuZiHuaRongDao_GameStorage.data[ShuZiHuaRongDao_GameData.Game_mode].best_time);
        // this.Label_step_number_record.string = `${ShuZiHuaRongDao_GameStorage.data[ShuZiHuaRongDao_GameData.Game_mode].step_number}`;
    }
    AddListener() {
        this.Button_menu.on(Node.EventType.TOUCH_END, this.On_Button_menu, this);
        this.Button_replay.on(Node.EventType.TOUCH_END, this.On_Button_replay, this);
    }
    RemoveListener() {
        this.Button_menu.off(Node.EventType.TOUCH_END, this.On_Button_menu, this);
        this.Button_replay.off(Node.EventType.TOUCH_END, this.On_Button_replay, this);
    }
    On_Button_menu() {
        this.ShowOff();
        SSS_GameEventManager.eventTarget.emit(SS_GameEventData.Menu);
        SSS_AudioManager.PlayButtonAudio();
    }
    On_Button_replay() {
        this.ShowOff();
        SSS_GameEventManager.eventTarget.emit(SS_GameEventData.Replay);
    }
}